package com.example.demo.repository;

import com.example.demo.entity.basic.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public interface UserRepository extends JpaRepository<User,Long> {

    //查询位于某个年龄段的人员信息
    List<User> findByAgeBetween(Long start, Long end);

    //对name进行模糊查询
    List<User> findByNameLike(String name);

    //JPQL的用法演示
    @Query(value = "from User")
    List<User> jpqlFindAll();
    @Query(value = "from User where name = ?1")
    User jpqlFindByName(String name);


    //原生本地sql演示
    //对数据库有变化的操作，应该额外添加一个注解： @Modifying
    @Query(nativeQuery=true, value = "select * FROM user where name like ?1 and age BETWEEN ?2 and ?3 ORDER BY id ASC")
    List<User> localSql(String name, Long age1, Long age2);

}
